package cc.bailongma.me.adapter;

import java.util.List;

import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cc.bailongma.me.R;
import cc.bailongma.me.entity.Location;

public class LocationListAdapter extends BaseAdapter{
	private Activity activity;
	private List<Location> locations;
		public LocationListAdapter(FragmentActivity activity,
			List<Location> locations) {
		this.locations=locations;
		this.activity=activity;
	}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return locations.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return locations.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder vh=null;
			if(convertView==null){
				convertView=LayoutInflater.from(activity).inflate(R.layout.list_item_position, null);
				vh=new ViewHolder();
				vh.date=(TextView) convertView.findViewById(R.id.tv_date);
				vh.time=(TextView) convertView.findViewById(R.id.tv_time);
				vh.location=(TextView) convertView.findViewById(R.id.tv_location);
				vh.state=(TextView) convertView.findViewById(R.id.tv_state);
				convertView.setTag(vh);
			}
			Location location=locations.get(position);
			vh=(ViewHolder) convertView.getTag();
			vh.date.setText(location.getDate());
			vh.time.setText(location.getTime());
			vh.location.setText(location.getLocation());
			vh.state.setText(location.getState());
			return convertView;
		}
		class ViewHolder{
			TextView date;
			TextView time;
			TextView location;
			TextView state;
		}
}
